//
//  JQFYGenreMusicInfoCollectionViewCell.m
//  JQFY
//
//  Created by 代辉 on 2017/11/3.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYGenreMusicInfoCollectionViewCell.h"
#import "JQFYGenreSongInfoCollectionViewCell.h"

@interface JQFYGenreMusicInfoCollectionViewCell () <UICollectionViewDelegate,UICollectionViewDataSource>


@end

static NSString *CELL_ID = @"JQFYGenreSongInfoCollectionViewCell";
@implementation JQFYGenreMusicInfoCollectionViewCell
{
    UICollectionView *_genreCollection;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
    layout.itemSize = CGSizeMake(328 *0.5 *SCAL, 0.5 * 415 *SCAL);
    
    _genreCollection = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    _genreCollection.showsVerticalScrollIndicator = NO;
    _genreCollection.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:_genreCollection];
    [_genreCollection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(20 *SCAL);
        make.left.equalTo(self.contentView).offset(15 *SCAL);
        make.right.equalTo(self.contentView).offset(-15 *SCAL);
        make.bottom.equalTo(self);
    }];
    _genreCollection.dataSource = self;
    _genreCollection.delegate = self;
    [_genreCollection registerClass:[JQFYGenreSongInfoCollectionViewCell class] forCellWithReuseIdentifier:CELL_ID];
//    _genreCollection.contentInset = UIEdgeInsetsMake(20 *SCAL, 10 *SCAL, 0, -10 *SCAL);
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.songInfo.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    JQFYGenreSongInfoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CELL_ID forIndexPath:indexPath];
    cell.songInfo = self.songInfo[indexPath.row];
    return cell;
}
- (void)setSongInfo:(NSArray *)songInfo
{
    _songInfo = songInfo;
    [_genreCollection reloadData];
}
@end
